#include "city_modify_dialog.h"
#include "ui_city_modify_dialog.h"

city_modify_Dialog::city_modify_Dialog(QSet<QString>& City_name, QSet<QString>& Country_name, City &city, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::city_modify_Dialog),
    cit(city),
    city_name(City_name),
    country_name(Country_name)
{
    ui->setupUi(this);
    for(auto e : city_name)
    {
        ui->comboBox_city->addItem(e);
    }
    for(auto e : country_name)
    {
        ui->comboBox_country->addItem(e);
    }

    ui->comboBox_country->setEditText(cit.get_country());
    ui->comboBox_city->setEditText(cit.get_name());
    ui->spinBox_new->setValue(cit.get_new());
    ui->spinBox_now->setValue(cit.get_now());
    ui->spinBox_cure->setValue(cit.get_cure());
    ui->spinBox_dead->setValue(cit.get_dead());
    ui->spinBox_all->setValue(cit.get_all());
}


city_modify_Dialog::~city_modify_Dialog()
{
    delete ui;
}

City city_modify_Dialog::get_city()
{
    return cit;
}

void city_modify_Dialog::on_pushButton_canle_clicked()
{
    this->close();
}

void city_modify_Dialog::on_pushButton_ok_clicked()
{
    QString country = ui->comboBox_country->currentText();
    QString name = ui->comboBox_city->currentText();
    QDate day = ui->dateEdit->date();
    int New = ui->spinBox_new->value();
    int now = ui->spinBox_now->value();
    int cure = ui->spinBox_cure->value();
    int dead = ui->spinBox_dead->value();
    int all = ui->spinBox_all->value();

    QMessageBox mess;
    if(country == "" || name == "" || New < 0 || now < 0 || cure < 0 || dead < 0 || all < 0)
    {
        mess.setText("输入数据有误，请检查!");
        mess.exec();
        return;
    }

    this->cit = City(name,country,New,now,all,cure,dead,day);
    this->accept();
    this->close();
}
